package com.example.ceramics.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DatabaseHelper extends SQLiteOpenHelper {
    public DatabaseHelper(@Nullable Context context) {
        super(context, DatabaseContants.DATABASE_NAME, null, DatabaseContants.VERSION_CODE);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table if not exists " + DatabaseContants.TABLE_USER +
                "(account varchar primary key," +
                "password varchar," +
                "name varchar," +
                "nickname varchar," +
                "phone varchar," +
                "email varchar," +
                "addressProvince varchar," +
                "addressCity varchar," +
                "addressCounty varchar," +
                "addressDetail varchar," +
                "img varchar)";
        db.execSQL(sql);
        sql = "create table if not exists " + DatabaseContants.TABLE_GOODS +
                "(goodsId integer primary key autoincrement," +
                "goodsName varchar," +
                "goodsPrice double," +
                "goodsSignature varchar," +
                "goodsType varchar," +
                "goodsImg integer)";
        db.execSQL(sql);
        sql = "create table if not exists " + DatabaseContants.TABLE_CART +
                "(account varchar," +
                "goodsId integer," +
                "num integer," +
                "price double," +
                "primary key(account,goodsId))";
        db.execSQL(sql);
        sql = "create table if not exists " + DatabaseContants.TABLE_ORDER +
                "(id integer primary key autoincrement," +
                "account varchar," +
                "goodsId integer," +
                "num integer," +
                "price double," +
                "time varchar)";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
